package io.renren.modules.quickService.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.quickService.vo.AreaCodeVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.quickService.entity.AreacodeEntity;
import io.renren.modules.quickService.service.AreacodeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 行政区划编码
 *
 * @author zenger380
 * @email zenger380@163.com
 * @date 2018-10-10 16:12:43
 */
@RestController
@RequestMapping("quickService/areacode")
public class AreacodeController {
    @Autowired
    private AreacodeService areacodeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quickService:areacode:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = areacodeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 区域列表
     */
    @RequestMapping("/adminCodeList")
    @RequiresPermissions("quickService:areacode:adminCodeList")
    public R countyList() {
        List<AreaCodeVO>  adminCodeList = areacodeService.getCascadeAreas();
        return R.ok().put("adminCodeList", adminCodeList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{areacodeId}")
    @RequiresPermissions("quickService:areacode:info")
    public R info(@PathVariable("areacodeId") Long areacodeId) {
        AreacodeEntity areacode = areacodeService.selectById(areacodeId);

        return R.ok().put("areacode", areacode);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("quickService:areacode:save")
    public R save(@RequestBody AreacodeEntity areacode) {
        areacodeService.insert(areacode);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("quickService:areacode:update")
    public R update(@RequestBody AreacodeEntity areacode) {
        areacodeService.updateById(areacode);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("quickService:areacode:delete")
    public R delete(@RequestBody Long[] areacodeIds) {
        areacodeService.deleteBatchIds(Arrays.asList(areacodeIds));

        return R.ok();
    }

}
